<?php namespace Common\Model;
use Hdphp\Model\Model;
class TypeAttr extends Model{
	//引入属性表
	protected $table = 'type_attr';
	//自动验证
	protected $validate = array(
		array('taname','required','属性名称不能为空',3,3),
		array('tavalue','required','属性值不能为空',3,3),
		array('class','required','请选择类别',3,3)
	);
	//添加
	public function store(){
		//触发自动验证
	    if($this->create()){
			$this->data['ygshop_type_tid'] = $_POST['ygshop_type_tid'];
			$this->add();
			return TRUE;
	    }else{
	    		return FALSE;
	    }
	}
	public function getTypeAttr(){
		$tid = Q('get.tid',0,'intval');

	    //获取全部数据
		$typeAttr = $this->where("ygshop_type_tid={$tid}")->count();
		//分页，6条数据一页
		$page = Page::row(6)->make($typeAttr);
		$typeAttrData = $this->where("ygshop_type_tid={$tid}")->limit(Page::limit())->get();
		$data = array(
			'page' => $page,
			'data' => $typeAttrData
		); 
		return $data;
	}
	//添加属性
	public function edit(){
	    if($this->create()){
	    		$this->save();
			return TRUE;
	    }else{
	    		return FALSE;
	    }
	}
	
}



 ?>